# -*- coding: utf-8 -*-
"""
Created on Tue Apr 04 09:55:39 2017

@author: Tubin Huang
"""

import csv

class Header(object):
    _name = ""
    _valid = False
    # placeholders
    fields = []
    requirement = ""
    caseNumber = ""

    def __init__(self):
        pass

def zipCSV( fileName ):
    with open(fileName, 'rb' ) as f:
        zipRows =  zip(*[x.split(',') for x in f.read().splitlines()]) 
        with open(f.name, 'wb') as w:
            writer = csv.writer(w)
            for row in zipRows:
                writer.writerow(row)
            
def dict2CSV( fileName, fields, rowdicts, writeheader=False, mode="wb"):
    with open(fileName,mode) as csvfile:    
        writer = csv.DictWriter(csvfile, fields)
        if writeheader == True:
            writer.writeheader()
        writer.writerows(rowdicts)
def getHeader(fileName, transfor = False):
    with open(fileName) as f:
        datalist = [x.split(',') for x in f.read().splitlines()]
        if transfor == True:
            datalist = zip(*datalist)
        return datalist[0]
    
def test():
    print getHeader("d:\\python\\output.csv", transfor=True) 
"""
    with open("d:\\python\\input.csv", "rb") as csvfile:
        reader = csv.DictReader(csvfile)
        dicts = []
        for dict in reader:
            dicts.append(dict)
        print dicts
        dict2CSV("d:\\python\\output.csv",["id","name","age"],dicts, transfor=True)
"""        
if __name__ == "__main__":
    test()